<?php
class ColumnAction extends CategoryCommonAction {
   public function __construct(){
		parent::__construct();
		
		$this->modelObject = D('Column');
		
		
  }
  
  public function add(){
		if(IS_POST){	
		
			//处理 column_type 和 column_value
			$columnType = I('column_type');
			$_POST['column_value'] = I($columnType, '');
			if(empty($_POST['column_value'])){
				$this->error('请选择或填写导航内容!');	
			}
				
			if($this->modelObject->create()){
				if($cateId =$this->modelObject->add()){
					
					/*cate_path*/
					$pid = I('pid', 0, 'intval');
					$this->setCatePath($pid, $cateId);
					
					$this->success('插入数据成功', U('index'));	
				}else{
					$this->error('插入失败!'.$this->modelObject->getError());
				}
			}else{
				$this->error('创建数据失败!'.$this->modelObject->getError());
			}
		}else{
			$this->assign('cateOption', $this->getCateOption());
			$this->assign('aboutOption', R('About/getList')); //基本文章
			$this->assign('joinOption', R('Join/getList')); //加盟文章
			$this->assign('goodsCateOption', R('GoodsCate/getCateOption')); //产品分类
			$this->assign('newsCateOption', R('NewsCate/getCateOption')); //文章分类
			$this->display();	
		}
	}
  
  	public function edit(){
		if(IS_POST){
			//处理 column_type 和 column_value
			$columnType = I('column_type');
			$_POST['column_value'] = I($columnType, '');
			if(empty($_POST['column_value'])){
				$this->error('请选择或填写导航内容!');	
			}
			
			if($this->modelObject->create()){
				if($this->modelObject->save()){
					/*cate_path*/
					$pid = I('pid', 0, 'intval');
					$cateId = I('id', 0, 'intval');
					$this->setCatePath($pid, $cateId);
					$this->success('编辑成功', U('index'));	
				}else{
					$this->error('编辑失败!'.$this->modelObject->getError());
				}
			}else{
				$this->error('创建数据失败!'.$this->modelObject->getError());
			}
		}else{
			$id = I('id', 0, 'intval');
			if($id){
				$info = $this->modelObject->getInfo($id);
				$this->assign('cateOption', $this->getCateOption());
				$this->assign('aboutOption', R('About/getList')); //基本文章
				$this->assign('joinOption', R('Join/getList')); //加盟文章
				$this->assign('goodsCateOption', R('GoodsCate/getCateOption')); //产品分类
				$this->assign('newsCateOption', R('NewsCate/getCateOption')); //文章分类
				$this->assign('info', $info);
				$this->display();	
			}else{
				$this->error('参数错误!');
			}
		}
	}
  
}//end class